//
//  MyMD5.m
//  ThreadDemo
//
//  Created by A5 on 14-10-21.
//  Copyright (c) 2014年 胡中磊. All rights reserved.
//

#import "MD5Encryption.h"
#import <CommonCrypto/CommonDigest.h>

@implementation MD5Encryption

// 对对传入的字符串进行md5加密,并返回加密后的字符串
+ (NSString *)getMd5WithString: (NSString *)mdString
{
    if ([mdString length] != 0)
    {
        const char *original_str = [mdString UTF8String];
        unsigned char result[CC_MD5_DIGEST_LENGTH];
        CC_MD5(original_str,(CC_LONG)strlen(original_str),result);
        NSMutableString *hash = [NSMutableString string];
        for (int i = 0; i < 16; i++)
        {
            [hash appendFormat:@"%02X", result[i]];
        }
        return [hash lowercaseString];
    }

    return nil;
}

@end
